package com.github.eventbusdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //EventBus.getDefault().register(this);
        initUI();
    }

    private void initUI() {
        Button linkBtn = findViewById(R.id.link_btn_id);
        linkBtn.setOnClickListener(this);
        Button sendBtn = findViewById(R.id.send_btn_id);
        sendBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.link_btn_id:

                break;
            case R.id.send_btn_id:
                MessageWrap wrap = new MessageWrap();
                wrap.setMessage("test");
                EventBus.getDefault().post(wrap);
                startActivity(new Intent(this, ReceiveActivity.class));
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //EventBus.getDefault().unregister(this);
    }

//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onMessage(MessageWrap messageWrap) {
//        Toast.makeText(this, messageWrap.getMessage(), Toast.LENGTH_SHORT).show();
//    }
}